#include "Scene/UserChangeScene.h"
#include "Scene/MainMenuScene.h"
#include "Other/User.h"
#include "ui/CocosGUI.h"
#include "cocos2d.h"
#include <iostream>
#include <string>
USING_NS_CC;
using namespace ui;

Scene* UserChangeScene::createScene() {
    return UserChangeScene::create();
}


// on "init" you need to initialize your instance
bool UserChangeScene::init() {
    if (!Scene::init()) {
        return false;
    }

    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    // 用户名字 Label对象
    auto usernameLabel = Label::createWithTTF("User   Name", "TypeFace/Marker Felt.ttf", 45);
    usernameLabel->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.65f));
    usernameLabel->setColor(Color3B::BLACK);
    this->addChild(usernameLabel);

    // 添加用户  文本框 
    auto adduserText = TextField::create("Enter your name", "TypeFace/Marker Felt.ttf", 25);
    adduserText->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.5f));
    // 可输入
    adduserText->setPasswordEnabled(true);
    // 最长10字母
    adduserText->setMaxLength(10);
    this->addChild(adduserText);

    // 添加用户的界面  

    auto spriteadduser = Sprite::create("Games/setting box2.png");
    spriteadduser->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.50f));
    spriteadduser->setScale(0.7f);
    this->addChild(spriteadduser, -1);

    auto name1 = Label::createWithTTF("RATIFY", "TypeFace/Marker Felt.ttf", 20);
    auto name2 = Label::createWithTTF("RATIFY", "TypeFace/Marker Felt.ttf", 20);
    auto item = MenuItemSprite::create(name1, name2, CC_CALLBACK_1(UserChangeScene::menuCloseCallback, this));
    item->setPosition(Vec2::ZERO);
    auto menu = Menu::create(item, nullptr);
    menu->setPosition(visibleSize.width * 0.3f, visibleSize.height * 0.25f);
    this->addChild(menu);

    auto name3 = Label::createWithTTF("EXIT", "TypeFace/Marker Felt.ttf", 20);
    auto name4 = Label::createWithTTF("EXIT", "TypeFace/Marker Felt.ttf", 20);
    auto item2 = MenuItemSprite::create(name3, name4, CC_CALLBACK_1(UserChangeScene::menuCloseCallback, this));
    item2->setPosition(Vec2::ZERO);
    auto menu2 = Menu::create(item2, nullptr);
    menu2->setPosition(visibleSize.width * 0.7f, visibleSize.height * 0.25f);
    this->addChild(menu2);

    // 添加背景
    auto bg= Sprite::create("Games/bg0.jpg");
    bg->setPosition(Vec2(origin.x + visibleSize.width * 0.5f, origin.y + visibleSize.height * 0.5f));
    bg->setScale(2.1f);
    this->addChild(bg, -2);

    return true;
}


void UserChangeScene::menuCloseCallback(Ref* pSender) {
    // 创建主菜单界面并跳转
    auto scene = MainMenuScene::createScene();
    Director::getInstance()->replaceScene(scene);
}